package format.bigdecimal;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;

/**
 * @author Cheng Jun
 * @version 1.0
 * Description: 通过分配“双十一”包裹给快递公司学习DecimalFormat API
 * @date 2019/9/5 13:30
 */
public class DecimalFormatStudy {

    public static void main(String[] args) {

        DecimalFormat decimalFormat = new DecimalFormat("00.000#");
        decimalFormat.setRoundingMode(RoundingMode.UP);
        decimalFormat.setPositivePrefix("+");
        decimalFormat.setNegativePrefix("&");
        String price = decimalFormat.format(11.01);
        String price1 = decimalFormat.format(-11.01);
        decimalFormat.setCurrency(Currency.getInstance(Locale.UK));
        System.out.println(decimalFormat.getCurrency().getDisplayName());
        System.out.println(decimalFormat.getCurrency().getSymbol());
        System.out.println(price);
        System.out.println(price1);

        DecimalFormat defaultDecimalFormat = new DecimalFormat("\u00a4#,###.00", new DecimalFormatSymbols(Locale.UK));
        String amount = defaultDecimalFormat.format(1111.01);
        System.out.println(amount);
        System.out.println(defaultDecimalFormat.getCurrency().getDisplayName());
        System.out.println(defaultDecimalFormat.getCurrency().getSymbol());

        DecimalFormat englishDecimalFormat = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.CHINA);
        englishDecimalFormat.format(11.03);
        System.out.println(englishDecimalFormat.getCurrency().getDisplayName());
        System.out.println(englishDecimalFormat.getCurrency().getSymbol());


        DecimalFormat zhiFormat = new DecimalFormat();
        zhiFormat.applyPattern("0.00000000000000E00");
        System.out.println(zhiFormat.format(1000000));
        System.out.println(zhiFormat.format(12345678.345));


        DecimalFormat percentFormat = new DecimalFormat();
        percentFormat.applyPattern("##0.00\u2030");
        System.out.println(percentFormat.format(0.00003052222));
    }
}
